{extend name='common/content' /}

{block name="button"}
<div class="nowrap pull-right" style="margin-top:10px">
    {if auth("$classuri/add")}
    <button data-open='{:url("$classuri/add")}' data-title="添加{$title}" class='layui-btn layui-btn-small'><i
            class='fa fa-plus'></i> 添加{$title}
    </button>
    {/if}
    {if auth("$classuri/del")}
    <button data-update data-field='delete' data-action='{:url("$classuri/del")}'
            class='layui-btn layui-btn-small layui-btn-danger'><i class='fa fa-remove'></i> 删除{$title}
    </button>
    {/if}
</div>
{/block}

{block name="content"}

    <!-- 自动完成输入框 30th Aug. 2018 By PP-->
    <!-- <script type="text/javascript" src="__STATIC__/plugs/autocompleter/js/jquery.min.js"></script> -->
    <!-- <script type="text/javascript" src="__STATIC__/plugs/autocompleter/js/jquery.autocompleter.js"></script> -->
    <!-- <script type="text/javascript" src="__STATIC__/plugs/autocompleter/js/main.js"></script> -->
    <!-- <link rel="stylesheet" href="__STATIC__/plugs/autocompleter/css/main.css?ver={:date('ymd')}"> -->
    <!-- <link rel="stylesheet" href="__STATIC__/plugs/autocompleter/css/normalize.css?ver={:date('ymd')}"> -->


<!-- 表单搜索 开始 -->
<form class="layui-form layui-form-pane form-search" action="__SELF__" onsubmit="return false" method="get">

    <div class="layui-form-item layui-inline">
        <label class="layui-form-label" style="width:auto">站点名称</label>
        <div class="layui-input-inline">
            <input name="title" value="{$Think.get.title|default=''}" placeholder="站点名称" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item layui-inline">
        <label class="layui-form-label" style="width:auto">管理员名称</label>
        <div class="layui-input-inline">
            <input name="admin_id" value="{$Think.get.admin_id|default=''}" placeholder="管理员名称" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item layui-inline">
        <label class="layui-form-label" style="width:auto">域名</label>
        <div class="layui-input-inline">
            <input name="domain" value="{$Think.get.domain|default=''}" placeholder="域名" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item layui-inline">
        <label class="layui-form-label" style="width:auto">所属地区</label>
        <div class="layui-input-inline">
            <select name='zone_id' class='layui-select'>
                <option value="">所属地区</option>
                {foreach $areaList as $val}
                {eq name='val.area_id' value='$Think.get.zone_id|default=0'}
                <option selected  value='{$val.area_id}'>{$val.spl}{$val.area_name}</option>
                {else/}
                <option  value='{$val.area_id}'>{$val.spl}{$val.area_name}</option>
                {/eq}
                {/foreach}
            </select>
        </div>
    </div>

    <div class="layui-form-item layui-inline">
        <div class="layui-input-inline">
            <button type="submit" class="btn btn-sm btn-white"><i class="fa fa-search"></i> 搜索</button>
        </div>
    </div>

</form>
<!-- 表单搜索 结束 -->

<form onsubmit="return false;" data-auto="" method="POST">
    <input type="hidden" value="resort" name="action"/>
    <!-- <div class="layui-form"> -->
    <table class="table table-hover">
        <thead>
        <tr>
            <th class='list-table-check-td'>
                <input data-none-auto="" data-check-target='.list-check-box' type='checkbox'/>
            </th>
            <th class='list-table-sort-td'>
                <button type="submit" class="layui-btn layui-btn-normal layui-btn-mini">排 序</button>
            </th>
            <th class='text-center'>ID</th>
            <th class='text-center'>名称</th>
            <!-- <th class='text-center'>LOGO</th> -->
            <th class='text-center'>地区</th>
            <th class='text-center'>模板</th>
            <!-- <th class='text-center'>站点类型</th> -->
            <th class='text-center'>管理员</th>
            <th class='text-center'>域名</th>
            <!-- <th class='text-center'>手机号</th> -->
            <!-- <th class='text-center'>电子邮箱</th> -->
            <!--<th class='text-center'>登录次数</th>
            <th class='text-center'>最后登录</th>-->
            <th class='text-center'>状态</th>
            <!-- <th class='text-center'>是否推荐</th> -->
            <th class='text-center'>操作</th>
        </tr>
        </thead>
        <tbody>
        {foreach $list as $key=>$vo}
        <tr>
            <td class='list-table-check-td'>
                <input class="list-check-box" value='{$vo.id}' type='checkbox'/>
            </td>
                <td class='list-table-sort-td'>
                    <input name="_{$vo.id}" value="{$vo.sort}" class="list-sort-input"/>
                </td>
            <td class='text-center'>{$vo.id}</td>
            <td class='text-center'>{$vo.title}</td>
            <!-- <td class='text-center'><img src="{$vo.pc_logo}" width="100" height="50"></td> -->
            <td class='text-center'>{$vo.zone_id|join_area_name}</td>
            <td class='text-center'>{$vo.temp_id|get_model_value='Temp','title'}</td>
            <!-- <td class='text-center'>{$vo.app_id|get_model_value='App','title'}</td> -->
            <td class='text-center'>{$vo.admin_id|get_model_value='SystemUser','username'}</td>
            <!-- <td class='text-center'><a href="http://{$vo.domain}" target="_blank">{$vo.domain}</a></td> -->
            <td class='text-center'>{$vo.domain}</td>
            <!-- <td class='text-center'>{$vo.phone|default="<span style='color:#ccc'>还没有设置手机号</span>"}</td> -->
            <!-- <td class='text-center'>{$vo.email|default="<span style='color:#ccc'>还没有设置邮箱</span>"}</td> -->
            <!--<td class='text-center'>{$vo.login_num|default="<span style='color:#ccc'>从未登录</span>"}</td>
            <td class='text-center'>{$vo.login_at|format_time|default="<span style='color:#ccc'>从未登录</span>"}</td>-->
            <td class='text-center'>
                {if $vo.status eq 1}
                <span>已禁用</span>
                {elseif $vo.status eq 0}
                <span style="color:#090">使用中</span>
                {/if}
            </td>
<!--             <td class='text-center'>
                <input type="checkbox" name="is_recommoned" value="{$vo.id}" lay-filter="is_recommoned" lay-skin="switch" lay-text="是|否" {if $vo.is_recommoned eq 1}checked{/if}>
            </td> -->
            <td class='text-center nowrap'>

                <div class="layui-btn-group">
                    <!-- <a type="button" href="http://{$vo.app_id|get_model_value='App','url'}/admin/login/autologin?uid={$vo.admin_id}&sid={:session('user.id')}" target="_blank" class="layui-btn layui-btn-primary layui-btn-small">管理</a> -->

                    <a href="http://{$vo.domain}?d={$vo.id}" target="_blank" class="layui-btn layui-btn-primary layui-btn-small">访问</a>
                    
                    <!-- <a type="button" data-admin_id="{$vo.admin_id}" data-pass="{$vo.admin_id|get_model_value='SystemUser','password'}" data-url="{$vo.app_id|get_model_value='App','url'}/autologin/{$vo.admin_id}/{$vo.admin_id|get_model_value='SystemUser','password'|base64_encode}" target="_blank" class="layui-btn layui-btn-primary layui-btn-small op_domain">管理</a> -->

                    <!--{if auth("admin/grave/add")}-->
                    <!--<button type="button" data-modal='{:url("admin/grave/add")}?id={$vo.id}' class="layui-btn layui-btn-primary layui-btn-small">陵园添加</button>-->
                    <!--{/if}-->

<!--                     {if auth("$classuri/auth")}
                    <button type="button" data-modal='{:url("$classuri/auth")}?id={$vo.id}' class="layui-btn layui-btn-primary layui-btn-small">授权</button>
                    {/if} -->

<!--                     {if auth("$classuri/pass")}
                    <button type="button" data-modal='{:url("$classuri/pass")}?id={$vo.id}' class="layui-btn layui-btn-primary layui-btn-small">密码</button>
                    {/if} -->

                    {if $vo.status eq 0 and auth("$classuri/forbid")}
                    <button type="button" data-update="{$vo.id}" data-field='status' data-value='1' data-action='{:url("$classuri/forbid")}' class="layui-btn layui-btn-primary layui-btn-small">禁用</button>
                    {elseif auth("$classuri/resume")}
                    <button type="button" data-update="{$vo.id}" data-field='status' data-value='0' data-action='{:url("$classuri/resume")}' class="layui-btn layui-btn-primary layui-btn-small">启用</button>
                    {/if}

                    {if auth("$classuri/edit")}
                    <button type="button" data-open='{:url("$classuri/edit")}?id={$vo.id}' class="layui-btn layui-btn-primary layui-btn-small"><i class="layui-icon"></i></button>
                    {/if}

                    {if auth("$classuri/del")}
                    <button type="button" data-update="{$vo.id}" data-field='delete' data-action='{:url("$classuri/del")}' class="layui-btn layui-btn-primary layui-btn-small"><i class="layui-icon"></i></button>
                    {/if}
                </div>
            </td>
        </tr>
        {/foreach}
        </tbody>
    </table>
    {if isset($page)}<p>{$page}</p>{/if}
    <!-- </div> -->
</form>

<!--     <script type="text/javascript">
    var data = [
    { "value": "1", "label": "one" },
    { "value": "2", "label": "two" },
    { "value": "3", "label": "three" }
];
$(function () {
    $('#domain').autocompleter({ source: '/admin/domain/_getAdminUs' });
});
    </script> -->

<script>window.form.render();</script>
<script>
    layui.use('form', function(){
        var $ = layui.jquery, form = layui.form;

        //全选
        form.on('checkbox(allChoose)', function(data){
            var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
            child.each(function(index, item){
                item.checked = data.elem.checked;
            });
            form.render('checkbox');
        });

    });

    form.on('switch(is_recommoned)', function(data){
        var status=data.elem.checked;//新品状态 true:1是  false:0否
        var id=data.elem.value;//商品自增id
        $.ajax({
            url:'{:url("admin/domain/is_recommoned")}',
            type:"POST",
            data:{'is_recommoned':status,'id':id},
            dataType:"json",
            /*success:function(json){
             alert(json);
             },
             error:function(res){
             alert(res);
             }*/
        });
    });

    $(".op_domain").click(function(){
        var admin_id = $(this).attr("data-admin_id");
        var pass = $(this).attr("data-pass");
        var url = $(this).attr("data-url");
        // alert(url);
        if(!pass){
            alert("请先设置管理员密码");return false;
        }
        // window.location.href = url;
        window.open(url);
    })

</script>
{/block}